package com.qyzmt.controller;

import com.qyzmt.pojo.LoginToken;
import com.qyzmt.pojo.Result;
import com.qyzmt.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping("/api/admin")
@RestController
public class LoginController {

    @Autowired
    private LoginService loginService;
    @PostMapping("/login")
    public Result login(@RequestBody LoginToken loginToken){
        LoginToken loginToken2 = loginService.login(loginToken);
        log.info("用户登录:{}，系统返回:{}",loginToken,loginToken2);
        if(Integer.parseInt(loginToken2.getAuthid()) != -1){
            return Result.success(loginToken2);
        }
        else{
            return Result.error("用户名或密码错误！");
        }


    }

}
